//用户收藏
exports.addConsultUser = function (req, res) {

    //获取bodyParams参数
    var bodyParams = req.routeInfo.bodyParams;
    // ////console.log(bodyParams);

    //最终结果
    var resultData = {};

    var forumActivityData = 0;
    //任务流创建
    async.waterfall([

            //1.信息查询
            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.searchOrganizationConsultUser + "/count/1/aocu_phone/" + bodyParams.aocu_phone,
                        method: 'POST',
                        data: {
                            aocu_phone: bodyParams.aocu_phone
                        }
                    },
                    function (err, data) {
                        ////console.log(data);
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }

                        if (data.count > 0) {
                            return RES.response(res, false, "您已提交过信息，我们会第一时间与您联系！");
                        } else {
                            //3.添加数咨询客户数据
                            R.SEND_HTTP(
                                req,
                                {
                                    url: CORE_APIConfig.coreAPI.addOrganizationConsultUser,
                                    method: 'POST',
                                    data: {
                                        aocu_name: bodyParams.aocu_name,
                                        aocu_type: bodyParams.aocu_type,
                                        aocu_member: bodyParams.aocu_member,
                                        aocu_phone: bodyParams.aocu_phone,
                                        aocu_address: bodyParams.aocu_address,
                                    }
                                },
                                function (err, data) {
                                    //判断是否有错误信息
                                    if (err) {
                                        return RES.response(res, false, "咨询用户添加失败");
                                    }
                                    resultData = data;
                                    cb();
                                }
                            );

                        }

                    }
                );

            },

            function (cb) {
                R.SEND_HTTP(
                    req,
                    {
                        url: "http://manage.hxzbi.com:3500/weixin/templateMessagesSent",
                        method: 'POST',
                        data: {
                            "type": "shiYongShenQing",
                            "openid": "oNriK0a6gZiAXJjGNWAqFe4eTydg",//胡莎
                            "name": bodyParams.aocu_name,
                            "tel": bodyParams.aocu_phone,
                            "goUrls": "http://manage.hxzbi.com/#/freeConsultingList"
                        }
                    },
                    function (err, data) {
                        console.log(data)
                        //判断是否有错误信息
                        if (err) {
                            return RES.response(res, false, data);
                        }
                        cb();
                    }
                );
            }


        ], function (err, result) {

            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}